package io;

import java.io.*;
import java.util.Scanner;

/**
 * @author krystal
 * @date 2022/11/27 10:50
 */
public class Demo13 {
    public static void main(String[] args) {
        //输入源文件和目标文件
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入源文件：");
        File srcFile=new File(scanner.next());
        System.out.println("请输入目标文件：");
        File destFile=new File(scanner.next());
        if (!srcFile.isFile()){
            System.out.println("输入的源文件有误！");
            return;
        }
        if (!destFile.getParentFile().isDirectory()){
            System.out.println("输入的目标文件有误！");
            return;
        }

        //打开源文件，按照字节读取内容，依次写入到目标文件中
        try (InputStream inputStream=new FileInputStream(srcFile);
             OutputStream outputStream=new FileOutputStream(destFile)){
            //读src的每个字节，写到dest中
            while (true){
                int ret=inputStream.read();
                if (ret==-1){
                    break;
                }
                outputStream.write(ret);
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
